package models

import (
	"gorm.io/gorm"
	"time"
)

// GameRoom 游戏房间模型
type GameRoom struct {
	gorm.Model
	Name      string    `json:"name" gorm:"size:100;not null"`
	RoomID    string    `json:"room_id" gorm:"size:50;not null"`
	GameType  string    `json:"game_type" gorm:"size:30"`
	Status    string    `json:"status" gorm:"size:20"`    // waiting, playing, finished
	Players   string    `json:"players" gorm:"type:text"` // JSON数组字符串
	StartTime time.Time `json:"start_time"`
	EndTime   time.Time `json:"end_time"`
}

func CreateGameRoom(room *GameRoom) error {
	return GetDB().Create(room).Error
}

func GetGameRooms() ([]GameRoom, error) {
	var rooms []GameRoom
	err := GetDB().Find(&rooms).Error
	return rooms, err
}

func UpdateGameRoomStatus(roomID, status string) error {
	return GetDB().Model(&GameRoom{}).Where("room_id = ?", roomID).Update("status", status).Error
}
